<?php
	class Membership {
		public function validate_user() {
			$db = new DBAccess();
			session_start();
			$valid = $db->verify_credentials();
			if($valid == "logged"){
				header('location: index.php?logged=true');
				return "logged";
			}
			else if($valid == "true") {
				$_SESSION['status'] = 'auth';
				$this->check_session();
				header('location: php/desktop.php');
				return "true";
			}
			return "false";
		}
		
		public function Logout() {
			$db = new DBAccess();
			$db->Logoff();
			if(isset($_SESSION['status'])) {
				unset($_SESSION['status']);

				if(isset($_COOKIE[session_name()])) 
					setcookie(session_name(), '', time() - 1000);
				 session_destroy();
			}
		}


		public function CheckAddUser() {
			$db = new DBAccess();
			$success = $db->RegisterUser();
			if($success){
				return true;
			}
			return false;
		}

        public function CreateFileSystem(){
                mkdir("users/".$_POST['username'], 0777);
                chmod("users/".$_POST['username'], 0777);
                mkdir("users/".$_POST['username']."/Documents", 0777);
                chmod("users/".$_POST['username']."/Documents", 0777);
                mkdir("users/".$_POST['username']."/Pictures", 0777);
                chmod("users/".$_POST['username']."/Pictures", 0777);
        }
        
		public function check_session() {
			session_start();
			if($_SESSION['status'] != 'auth')
				header('location: ../index.php');
		}
	}
?>
